using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Data;
using OpenComposite.Base;
using System.Windows.Forms;
using System.Xml.Schema;
using System.IO;
using OpenComposite.Repository.Properties;
using System.Drawing;
using System.ComponentModel;

namespace OpenComposite.EII.Repository
{
	#region Enum: ItemType
	public enum ItemType
	{
		Undefined = 0,
		// Base Repository Items
		Domain = 1,
		/// <summary>
		/// Vocabulary
		/// </summary>
		Noun = 4,
		Component = 6,
		Operation = 8,
		BRule = 10,
		BObject = 12,
		Capability = 84,
		ExposedCapability = 86,
		/// <summary>
		/// Capability Method
		/// </summary>
		Verb = 14,
		LogicalMethodGroup = 85,
		LogicalWebMethod = 81,
		Repository = 15,
		GenericFolder = 16,
		BPolicy = 17,
		// generic item types
		Container = 18,
		Route = 19,
		Label = 20,
		Separator = 62,
		// process symbols
		And = 21,
		Or = 22,
		XOr = 23,
		While = 24,
		Activity = 45,
		// org designer
		Organization = 25,
		OrgUnit = 26,
		Group = 27,
		Role = 28,
		User = 29,
		// rule (designer)
		BRule_If = 30,
		BRule_ThenElse = 31,
		BRule_And = 32,
		BRule_Or = 38,
		RuleConstant = 74,
		// sca diagram
		SCA_Export = 33,
		SCA_Import = 34,
		SCA_StandaloneReference = 35,
		//SCA_ServiceModule = 36,
		Composite = 36,
		CompositeReference = 68,
		SCA_External = 39,
		OrchestrationComponent = 49,
		RuleComponent = 50,
		HumanComponent = 51,
		SQLComponent = 52,
		UIComponent = 75,
		// diagram
		Diagram = 37,
		Business_SCA = 53,
		SOBA = 54,
		SOA = 61,
		// fachabteilung
		FA_View = 40,
		FA_Domain = 41,
		FA_Service = 42,
		// it structure
		ITObject = 43,
		BObjectIcon = 44,
		Selector = 46,
		System = 47,
		Mapping = 48,
		// business process
		Business_Process = 55,
		BProcess_Start = 56,
		BProcess_End = 57,
		// .net workflow
		Workflow = 58,
		LogicalActivity = 67,
		Workflow_Method = 77,
		Workflow_Event = 78,
		Workflow_Field = 79,
		// end points
		WebService = 59,
		APIService = 83,
		WebMethod = 60,
		MessageQueue = 88,
		// KPIs
		KPI = 63,
		KPI_Metric = 64,
		KPI_Function = 65,
		KPI_Schedule = 66,
		// BUS View
		BUS = 69,
		BUSActivity = 70,
		BUSDocument = 71,
		BUSPublish = 72,
		BUSSubscribe = 73,
		BUSVariables = 82,
		// Human Activities
		HumanActivity = 76,
		// Mashups
		// last of V1.0Singhammer/V0.9Beta
		Mashup = 80,
		// Documentation
		Documentation = 87
	}
	#endregion

	public static class ItemTypes
	{
		public static void Init()
		{
			_dicDisplay = new Dictionary<ItemType, string>();
			DataTable dt = Global.Data.GetRepositoryTypes();
			if ( dt != null ) {
				foreach ( DataRow row in dt.Rows ) {
					_dicDisplay.Add((ItemType)row["reptype_id"], row["reptype_display"].ToString());
				}
			}
			_dicDisplay[ItemType.Capability] = "Service";
			_dicDisplay[ItemType.Verb] = "Capability";
			_dicDisplay[ItemType.LogicalWebMethod] = "Logical Method";
			_dicDisplay[ItemType.Workflow] = "Process";
		}
		private static Dictionary<ItemType, string> _dicDisplay = null;

		public static string GetDisplay(ItemType type)
		{
			if ( _dicDisplay == null )
				ItemTypes.Init();

			return _dicDisplay.ContainsKey(type) ? _dicDisplay[type] : _dicDisplay[ItemType.Undefined];
		}
		public static string GetDisplay(ItemType[] types)
		{
			if ( _dicDisplay == null )
				ItemTypes.Init();

			StringBuilder display = new StringBuilder();

			foreach ( ItemType type in types ) {
				if ( _dicDisplay.ContainsKey(type) ) {
					if ( display.Length > 0 )
						display.Append(", ");
					display.Append(_dicDisplay[type]);
				}
			}
			return display.ToString();
		}

		public static Image GetImage(ItemType type)
		{
			Image img = null;
			switch ( type ) {
				case ItemType.Undefined:
					break;
				case ItemType.Domain:
					img = Resources.domain;
					break;
				case ItemType.Noun:
					img = Resources.png_field;
					break;
				case ItemType.Component:
					break;
				case ItemType.Operation:
					break;
				case ItemType.BRule:
					img = Resources.png_brule;
					break;
				case ItemType.BObject:
					img = Resources.bobject;
					break;
				case ItemType.Capability:
					img = Resources.png_capability;
					( (Bitmap)img ).MakeTransparent(Color.Magenta);
					break;
				case ItemType.ExposedCapability:
					break;
				case ItemType.Verb:
					img = Resources.verb;
					break;
				case ItemType.LogicalMethodGroup:
					img = Resources.png_logical_method_group;
					break;
				case ItemType.LogicalWebMethod:
					img = Resources.png_logical_method;
					break;
				case ItemType.Repository:
					break;
				case ItemType.GenericFolder:
					break;
				case ItemType.BPolicy:
					img = Resources.policy;
					( (Bitmap)img ).MakeTransparent(Color.Magenta);
					break;
				case ItemType.Container:
					break;
				case ItemType.Route:
					break;
				case ItemType.Label:
					break;
				case ItemType.Separator:
					break;
				case ItemType.And:
					break;
				case ItemType.Or:
					break;
				case ItemType.XOr:
					break;
				case ItemType.While:
					break;
				case ItemType.Activity:
					break;
				case ItemType.Organization:
					img = Resources.png_org;
					break;
				case ItemType.OrgUnit:
					img = Resources.png_org_unit;
					break;
				case ItemType.Group:
					img = Resources.domain;
					( (Bitmap)img ).MakeTransparent(Color.Magenta);
					break;
				case ItemType.Role:
					img = Resources.png_users;
					break;
				case ItemType.User:
					img = Resources.png_user;
					break;
				case ItemType.BRule_If:
					break;
				case ItemType.BRule_ThenElse:
					break;
				case ItemType.BRule_And:
					break;
				case ItemType.BRule_Or:
					break;
				case ItemType.RuleConstant:
					img = Resources.png_constant;
					break;
				case ItemType.SCA_Export:
					break;
				case ItemType.SCA_Import:
					break;
				case ItemType.SCA_StandaloneReference:
					break;
				case ItemType.Composite:
					img = Resources.png_orchestration;
					break;
				case ItemType.CompositeReference:
					break;
				case ItemType.SCA_External:
					break;
				case ItemType.OrchestrationComponent:
					break;
				case ItemType.RuleComponent:
					break;
				case ItemType.HumanComponent:
					img = Resources.png_user;
					break;
				case ItemType.SQLComponent:
					break;
				case ItemType.UIComponent:
					break;
				case ItemType.Diagram:
					break;
				case ItemType.Business_SCA:
					break;
				case ItemType.SOBA:
					break;
				case ItemType.SOA:
					break;
				case ItemType.FA_View:
					break;
				case ItemType.FA_Domain:
					break;
				case ItemType.FA_Service:
					break;
				case ItemType.ITObject:
					break;
				case ItemType.BObjectIcon:
					break;
				case ItemType.Selector:
					break;
				case ItemType.System:
					break;
				case ItemType.Mapping:
					img = Resources.bmp_mapping;
					( (Bitmap)img ).MakeTransparent(Color.Magenta);
					break;
				case ItemType.Business_Process:
					img = Resources.png_horizontalprocess;
					break;
				case ItemType.BProcess_Start:
					break;
				case ItemType.BProcess_End:
					break;
				case ItemType.Workflow:
					img = Resources.png_orchestration;
					break;
				case ItemType.LogicalActivity:
					break;
				case ItemType.Workflow_Method:
					img = Resources.method;
					( (Bitmap)img ).MakeTransparent(Color.Magenta);
					break;
				case ItemType.Workflow_Event:
					img = Resources.png_event;
					( (Bitmap)img ).MakeTransparent(Color.Magenta);
					break;
				case ItemType.Workflow_Field:
					img = Resources.png_field;
					( (Bitmap)img ).MakeTransparent(Color.Magenta);
					break;
				case ItemType.WebService:
					img = Resources.png_webservice;
					break;
				case ItemType.APIService:
					break;
				case ItemType.WebMethod:
					img = Resources.method;
					( (Bitmap)img ).MakeTransparent(Color.Magenta);
					break;
				case ItemType.KPI:
					break;
				case ItemType.KPI_Metric:
					break;
				case ItemType.KPI_Function:
					break;
				case ItemType.KPI_Schedule:
					break;
				case ItemType.BUS:
					img = Resources.png_bus;
					break;
				case ItemType.BUSActivity:
					break;
				case ItemType.BUSDocument:
					break;
				case ItemType.BUSPublish:
					break;
				case ItemType.BUSSubscribe:
					break;
				case ItemType.BUSVariables:
					break;
				case ItemType.HumanActivity:
					img = Resources.png_user;
					break;
				case ItemType.Mashup:
					img = Resources.png_mashup;
					break;
				default:
					break;
			}

			return img;
		}

		/// <summary>
		/// Returns true if an RepositoryItem associated with an specific ItemTyp has a Diagram, otherwise false.
		/// </summary>
		/// <param name="type">ItemType to check for diagram</param>
		/// <returns>true if ItemType has diagram, otherwise false</returns>
		public static bool HasDiagram(ItemType type)
		{
			switch ( type ) {
				case ItemType.BRule:
				case ItemType.BObject:
				case ItemType.Capability:
				case ItemType.ExposedCapability:
				case ItemType.BPolicy:
				case ItemType.Composite:
				case ItemType.CompositeReference:
				case ItemType.Diagram:
				case ItemType.Business_Process:
				case ItemType.Workflow:
				case ItemType.Mashup:
					return true;
				default:
					return false;
			}
		}
	}
}
